﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using AMatysiak.Methods;
using System;

namespace AMatysiakTest.Methods
{
    [TestClass]
    public class FormatNamedTest
    {
        private class Test
        {
            public string A { get; set; }
            public double B { get; set; }
            public int C { get; set; }

            public DateTime D { get; set; }

            public string this[int key]
            {
                get { return "B"; }
                set { }
            }

            public string this[string key]
            {
                get { return "A"; }
                set { }
            }
        }

        private class Test2
        { }

        [TestMethod]
        public void emptyPattern()
        {
            Test test = new Test();
            string text = "".FormatNamed(test);
            Assert.AreEqual("", text);
        }

        [TestMethod]
        public void testIndexer()
        {
            Test test = new Test() { A = "A" };
            string text = "ind[d] = {5} {A}".FormatNamed(test);
            Assert.AreEqual("ind[d] = B A", text);
        }

        [TestMethod]
        public void oneArg()
        {
            Test test = new Test() { A = "A"};
            string text = "a = {A}".FormatNamed(test);
            Assert.AreEqual("a = A", text);
        }

        [TestMethod]
        public void twoArgs()
        {
            Test test = new Test() { A = "A", B = 5.1 };
            string text = "a = {A}, b = {B}".FormatNamed(test);
            Assert.AreEqual("a = A, b = 5,1", text);
        }

        [TestMethod]
        public void threeArgs()
        {
            Test test = new Test() { A = "A", B = 5.1, C = 3 };
            string text = "a = {A}, b = {B}, c = {C}".FormatNamed(test);
            Assert.AreEqual("a = A, b = 5,1, c = 3", text);
        }

        [TestMethod]
        [ExpectedException(typeof(FormatException))]
        public void undefinedArg()
        {
            Test2 test = new Test2();
            "{E}".FormatNamed(test);
        }

        [TestMethod]
        public void undefinedArgWithoutException()
        {
            Test test = new Test();
            string text = "{E}".FormatNamed(test, true);
            Assert.AreEqual("A", text);
        }

        [TestMethod]
        public void getIntIndexer()
        {
            Test test = new Test();
            string text = "[2] = {2}".FormatNamed(test, true);
            Assert.AreEqual("[2] = B", text);
        }

        [TestMethod]
        public void formatArg()
        {
            Test test = new Test() { B = 5.25 };
            string text = "{B:c}".FormatNamed(test);
            Assert.AreEqual("5,25 zł", text);
        }

        [TestMethod]
        public void sendDateTime()
        {
            Test test = new Test() { D = DateTime.Now };
            string text = "data = {D}".FormatNamed(test);
            Assert.AreEqual("data = " + DateTime.Now.ToString(), text);
        }
    }
}
